<template>
  <div class="jyzt">
    <el-row :gutter="20">
      <el-col :sm="24" :lg="24" style="margin-top: 20px">
        <el-card v-loading="loading" element-loading-text="Loading..." element-loading-background="#178af01a">
          <div v-for="el in tableData" :key="el.title" class="tableItem" @click="handleDetail(el)">
            <div class="left">
              <img style="width: 100%; height: 100%" :src="getUrl(el.picture)" alt="" />
            </div>
            <div class="right">
              <div class="top">
                <div class="title">{{ el.title }}</div>
                <div class="content">{{ el.introduction }}</div>
              </div>
              <div class="time">{{ el.fbsj }}</div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-dialog v-model="dialog.visible" class="customDialog" :title="dialog.title" width="800px">
      <div class="wzcontent">
        <div class="title">{{ form.title }}</div>
        <div class="source">
          <span style="margin-right: 10px">{{ form.source }}</span>
          <span>{{ form.fbsj }}</span>
        </div>
        <div class="content" v-html="form.content"></div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup lang="ts">
import useMapStore from '@/store/modules/map';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const $szxcapi = (proxy as any)?.$szxcapi;
const loading = ref(false);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  total: 0,
  hylb: ''
});
const tableData = ref([
  {
    picture: 'wuyu1',
    title: '2024年上班年役前教育人员名单公示',
    introduction: '经区征兵领导小组研究，确定我镇黄金龙等7名青年参加上半年役前教育训练，现将参训人员相关信息予以公示，接受广大群众监督、举报。',
    fbsj: '2024-02-08'
  },
  {
    picture: 'wuyu1',
    title: '2024年上班年役前教育人员名单公示',
    introduction: '经区征兵领导小组研究，确定我镇黄金龙等7名青年参加上半年役前教育训练，现将参训人员相关信息予以公示，接受广大群众监督、举报。',
    fbsj: '2024-02-08'
  }
]);
// const demoFormRef = ref<ElFormInstance>();
const initFormData = {
  id: undefined,
  title: undefined,
  source: undefined,
  fbsj: undefined,
  content: undefined
};
const data = reactive({
  form: { ...initFormData }
});
const { form } = toRefs(data);
const dialog = reactive<DialogOption>({
  visible: false,
  title: '详情信息'
});
const reset = () => {
  form.value = { ...initFormData };
  // demoFormRef.value?.resetFields();
};
const handleDetail = async (el) => {
  reset();
  const _id = el?.id;
  const res = await $szxcapi.info({ id: _id });
  Object.assign(form.value, res.data);
  dialog.visible = true;
};
const getUrl = (icon) => {
  return new URL(icon, import.meta.url).href;
};
const init = async (flag) => {
  loading.value = true;
  if (flag) {
    queryParams.value.pageNum = 1;
  }
  const params = {
    'newsCategoryId': 101,
    ...queryParams.value
  };
  const data = await $szxcapi.pageQuery(params);
  tableData.value = data.rows;
  queryParams.value.total = data.total;
  loading.value = false;
};
onMounted(async () => {
  await nextTick();
  init(true);
});
</script>

<style lang="scss" scoped>
.jyzt {
  width: 100%;
  height: 100%;
  font-family: 'DingTalk';
  .el-card {
    max-height: calc(90vh - 200px) !important;
    background: #178af01a;
    border: none;
    overflow: hidden auto;
    .el-pagination {
      margin-top: 10px;
      display: flex;
      justify-content: flex-end;
    }
  }
  .tableItem {
    display: flex;
    color: white;
    height: 120px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(23, 138, 240, 0.2);
    cursor: pointer;
    .left {
      width: 160px;
      height: 100%;
      margin-right: 10px;
    }
    .right {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .top {
        .title {
          font-size: 18px;
          line-height: 30px;
        }
        .content {
          height: 100%;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
        }
      }
    }
  }
  .wzcontent {
    color: #fff;
    .title {
      font-size: 28px;
      text-align: center;
      margin-bottom: 14px;
    }
    .source {
      margin-bottom: 14px;
    }
    .content {
      font-size: 20px;
    }
  }
}
</style>
